#!/usr/bin/env python

import unittest

from amlnextbus.destination import Destination

class TestDestination(unittest.TestCase):
    def setUp(self):
        self.destination = Destination('10', '10_OB1', '5859')

    def testParseDestination(self):
        testStr1 = """
        parent.addOption(toStopSelector,
                         "Pacific Ave & Polk St",
                         "5851",
                         false,
                         true);  // specifies which item is selected
"""
        (name, symbol, restOfStr) = self.destination.parseDestination(testStr1)

        self.assertEquals(name, "Pacific Ave & Polk St")
        self.assertEquals(symbol, "5851")

        testStr2 = """
        parent.addOption(toStopSelector,
                         "Pacific Ave & Larkin St",
                         "5844",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Pacific Ave & Hyde St",
                         "5839",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Pacific Ave & Leavenworth St",
                         "5846",
                         false,
                         false);  // specifies which item is selected
"""
        expectedNameArr = ["Pacific Ave & Larkin St",
                           "Pacific Ave & Hyde St", 
                           "Pacific Ave & Leavenworth St"]
        expectedSymbolArr = ["5844", "5839", "5846"]

        (name, symbol, restOfHtmlStr) = self.destination.parseDestination(testStr2)
        i = 0
        while (restOfHtmlStr != None):
            self.assertEquals(name, expectedNameArr[i])
            self.assertEquals(symbol, expectedSymbolArr[i])
        
            i += 1
            (name, symbol, restOfHtmlStr) = self.destination.parseDestination(restOfHtmlStr)

    def testLoadDestinations(self):
        self.assertTrue(len(self.destination.nameArr) > 0)
        self.assertTrue(len(self.destination.symbolArr) > 0)

    def testGetName(self):
        self.assertEquals(self.destination.getName("5841"), "Pacific Ave & Jones St")
        self.assertEquals(self.destination.getName("5857"), "Pacific Ave & Taylor St")
        self.assertEquals(self.destination.getName("5848"), "Pacific Ave & Mason St")

    def testGetSymbol(self):
        self.assertEquals(self.destination.getSymbol("Pacific Ave & Powell St"), "5853")
        self.assertEquals(self.destination.getSymbol("Broadway & Stockton St"), "3087")
        self.assertEquals(self.destination.getSymbol("Broadway & Columbus"), "3082")


if __name__ == '__main__':
    unittest.main()


